<?
session_start();
$last_request = microtime();
if ($_SESSION['username'] == null) {
	if ($_POST['username'] == null) $_POST['username'] = 'taviroquai';
	$_SESSION['username'] = $_POST['username'];
	
	$manager = new Manager('teste');
	$_SESSION['manager'] = $manager;
	
	$conta_file = './save/contas/'. $_SESSION['username'] . '.obj';
	if (!file_exists($conta_file)) {
		include ('conta_registo.php');
		include ('pers_registo.php');
		include ('pers_enter.php');
	} else {
		$conta = $manager->readObj($_SESSION['username'], 'contas');
		$_SESSION['conta'] = $conta;
	}
	
	$_SESSION['ultimo_acesso'] = $conta->getValue('ultimo_acesso');
	
	$mapa = $manager->readObj('mapa1', 'mapas');
	$_SESSION['mapa'] = $mapa;
	
} else {
	$mapa		= $_SESSION['mapa'];
	$manager	= $_SESSION['manager'];
	$conta		= $_SESSION['conta'];
	$conta->actualizarTempo(floor(time()));
	$manager->writeObj($conta, 'username', 'contas');
}
?>